home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / gfx / misc / gnuplot-3.7src.lha / gnuplot-3.7src / gnuplot-3.7.lha / gnuplot-3.7 / docs / checkdoc.c next >
C/C++ Source or Header  |  1998-10-19  |  4KB  |  168 lines

  1. /*
  2.  * $Id: checkdoc.c,v 1.17 1998/04/14 00:16:57 drd Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - checkdoc.c */
  7.  
  8. /*[
  9.  * Copyright 1986 - 1993, 1998   Thomas Williams, Colin Kelley
  10.  *
  11.  * Permission to use, copy, and distribute this software and its
  12.  * documentation for any purpose with or without fee is hereby granted,
  13.  * provided that the above copyright notice appear in all copies and
  14.  * that both that copyright notice and this permission notice appear
  15.  * in supporting documentation.
  16.  *
  17.  * Permission to modify the software is granted, but not the right to
  18.  * distribute the complete modified source code.  Modifications are to
  19.  * be distributed as patches to the released version.  Permission to
  20.  * distribute binaries produced by compiling modified sources is granted,
  21.  * provided you
  22.  *   1. distribute the corresponding source modifications from the
  23.  *    released version in the form of a patch file along with the binaries,
  24.  *   2. add special version identification to distinguish your version
  25.  *    in addition to the base release version number,
  26.  *   3. provide your name and address as the primary contact for the
  27.  *    support of your modified version, and
  28.  *   4. retain our contact information in regard to use of the base
  29.  *    software.
  30.  * Permission to distribute the released version of the source code along
  31.  * with corresponding source modifications in the form of a patch file is
  32.  * granted with same provisions 2 through 4 for binary distributions.
  33.  *
  34.  * This software is provided "as is" without express or implied warranty
  35.  * to the extent permitted by applicable law.
  36. ]*/
  37.  
  38. /*
  39.  * checkdoc -- check a doc file for correctness of first column. 
  40.  *
  41.  * Prints out lines that have an illegal first character.
  42.  * First character must be space, digit, or ?, @, #, %, 
  43.  * or line must be empty.
  44.  *
  45.  * usage: checkdoc [docfile]
  46.  * Modified by Russell Lang from hlp2ms.c by Thomas Williams 
  47.  *
  48.  * Original version by David Kotz used the following one line script!
  49.  * sed -e '/^$/d' -e '/^[ 0-9?@#%]/d' gnuplot.doc
  50.  *
  51.  */
  52.  
  53. #ifdef HAVE_CONFIG_H
  54. #include "config.h"
  55. #endif
  56.  
  57. #include "ansichek.h"
  58. #include "stdfn.h"
  59. #include "doc2x.h"
  60.  
  61. void convert __PROTO((FILE *, FILE *));
  62. void process_line __PROTO((char *, FILE *));
  63.  
  64. int main(argc, argv)
  65. int argc;
  66. char **argv;
  67. {
  68.     FILE *infile;
  69.     infile = stdin;
  70.  
  71.     if (argc > 2) {
  72.     fprintf(stderr, "Usage: %s [infile]\n", argv[0]);
  73.     exit(EXIT_FAILURE);
  74.     }
  75.     if (argc == 2)
  76.     if ((infile = fopen(argv[1], "r")) == (FILE *) NULL) {
  77.         fprintf(stderr, "%s: Can't open %s for reading\n",
  78.             argv[0], argv[1]);
  79.         exit(EXIT_FAILURE);
  80.     }
  81.     convert(infile, stdout);
  82.     exit(EXIT_SUCCESS);
  83. }
  84.  
  85. void convert(a, b)
  86. FILE *a, *b;
  87. {
  88.     static char line[MAX_LINE_LEN+1];
  89.  
  90.     while (get_line(line, sizeof(line), a)) {
  91.     process_line(line, b);
  92.     }
  93. }
  94.  
  95. void process_line(line, b)
  96. char *line;
  97. FILE *b;
  98. {
  99.     /* check matching backticks within a paragraph */
  100.  
  101.     static int count = 0;
  102.  
  103.     if (line[0] == ' ') {
  104.     char *p = line;
  105.  
  106.     /* skip/count leading spaces */
  107.  
  108.     while (*++p == ' ');
  109.  
  110.     if (*p == '\n') {
  111.         /* it is not clear if this is an error, but it is an
  112.          * inconsistency, so flag it
  113.          */
  114.         fprintf(b, "spaces-only line %s:%d\n", termdoc_filename, termdoc_lineno);
  115.     } else {
  116.         /* accumulate count of backticks. Do not check odd-ness
  117.          * until end of paragraph (non-space in column 1)
  118.          */
  119.         for (; *p; ++p)
  120.         if (*p == '`')
  121.             ++count;
  122.     }
  123.     } else {
  124.     if (count & 1) {
  125.         fprintf(b,
  126.             "mismatching backticks before %s:%d\n",
  127.             termdoc_filename, termdoc_lineno);
  128.     }
  129.     count = 0;
  130.     }
  131.  
  132.     if (strchr(line, '\t'))
  133.     fprintf(b, "tab character in line %s:%d\n", termdoc_filename, termdoc_lineno);
  134.  
  135.     switch (line[0]) {        /* control character */
  136.     case '?':{            /* interactive help entry */
  137.         break;        /* ignore */
  138.     }
  139.     case '<':{            /* term docs */
  140.         break;        /* ignore */
  141.     }
  142.     case '@':{            /* start/end table */
  143.         break;        /* ignore */
  144.     }
  145.     case '#':{            /* latex table entry */
  146.         break;        /* ignore */
  147.     }
  148.     case '%':{            /* troff table entry */
  149.         break;        /* ignore */
  150.     }
  151.     case '^':{            /* html entry */
  152.         break;        /* ignore */
  153.     }
  154.     case '\n':            /* empty text line */
  155.     case ' ':{            /* normal text line */
  156.         break;
  157.     }
  158.     default:{
  159.         if (isdigit((int)line[0])) {    /* start of section */
  160.         /* ignore */
  161.         } else
  162.         /* output bad line */
  163.         fprintf(b, "%s:%d:%s", termdoc_filename, termdoc_lineno, line);
  164.         break;
  165.     }
  166.     }
  167. }
  168.